package com.hp.bon.sgw.wh.channel.groupConsistency;

import com.hp.bon.sgw.wh.channel.groupConsistency.BizSlot.*;
import com.hp.bon.sgw.wh.channel.invoices.BizSlot;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

public class ConsistencyBizRouter {

	private static final Logger _log = LoggerFactory.getLogger(ConsistencyBizRouter.class);

	private Map<String, BizSlot> slotRepositories = new HashMap<String, BizSlot>();

	public void init() {
		// 话费返还记录查询 QryReturnBalanceDetail
		String QryReturnBalanceDetailKey = "QryReturnBalanceDetail@POST";
		BizSlot qryReturnBalanceDetailSlot = new QryReturnBalanceDetailSlot();
		slotRepositories.put(QryReturnBalanceDetailKey, qryReturnBalanceDetailSlot);

		// 话费返还记录明细查询 QryReturnBalanceInfoDetail
		String QryReturnBalanceInfoDetailKey = "QryReturnBalanceInfoDetail@POST";
		BizSlot qryReturnBalanceInfoDetailSlot = new QryReturnBalanceInfoDetailSlot();
		slotRepositories.put(QryReturnBalanceInfoDetailKey, qryReturnBalanceInfoDetailSlot);

		// 余额变动汇总查询 QryBalanceRecord
		String QryBalanceRecordKey = "QryBalanceRecord@POST";
		BizSlot qryBalanceRecordSlot = new QryBalanceRecordSlot();
		slotRepositories.put(QryBalanceRecordKey, qryBalanceRecordSlot);

		// 余额变动明细查询 QryBalanceRecordDetail
		String QryBalanceRecordDetailKey = "QryBalanceRecordDetail@POST";
		BizSlot qryBalanceRecordDetailSlot = new QryBalanceRecordDetailSlot();
		slotRepositories.put(QryBalanceRecordDetailKey, qryBalanceRecordDetailSlot);

		// 余额查询 QueryBalance
		String QueryBalanceKey = "QueryBalance@POST";
		BizSlot queryBalanceSlot = new QueryBalanceSlot();
		slotRepositories.put(QueryBalanceKey, queryBalanceSlot);

		// 缴费销帐记录查询 QryPayment
		String QryPaymentKey = "QryPayment@POST";
		BizSlot qryPaymentSlot = new QryPaymentSlot();
		slotRepositories.put(QryPaymentKey, qryPaymentSlot);

		// 欠费查询 QryBill
		String QryBillKey = "QryBill@POST";
		BizSlot invoiceInformationGetSlot = new QryBillSlot();
		slotRepositories.put(QryBillKey, invoiceInformationGetSlot);

		// 帐单查询 QryCustBill
		String invoiceInformationKey = "QryCustBill@POST";
		BizSlot qryCustBillSlot = new QryCustBillSlot();
		slotRepositories.put(invoiceInformationKey, qryCustBillSlot);

		// 实时话费明细查询 QryInstantFeeList
		String QryInstantFeeListKey = "QryInstantFeeList@POST";
		BizSlot qryInstantFeeListSlot = new QryInstantFeeListSlot();
		slotRepositories.put(QryInstantFeeListKey, qryInstantFeeListSlot);

		// 橙分期 CreditProdFee
		String CreditProdFeeKey = "CreditProdFee@GET";
		BizSlot creditProdFeeSlot = new CreditProdFeeSlot();
		slotRepositories.put(CreditProdFeeKey, creditProdFeeSlot);
	}

	public BizSlot routeBizSlot(String requestPath, String requestMethod) {
		String key = requestPath + "@" + requestMethod.toUpperCase();
		BizSlot bizSlot = slotRepositories.get(key);
		if (null == bizSlot) {
			_log.error("none bizSlot,requestPath={},requestMethod={}", requestPath, requestMethod);
			Set<Entry<String, BizSlot>> entries = slotRepositories.entrySet();
			for (Entry<String, BizSlot> entry : entries) {
				_log.info("bizSlot, key={}, clz={}", entry.getKey(), entry.getValue().getClass());
			}
		}
		return bizSlot;
	}

}
